<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE>
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>主界面</title>

  </head>
  
  <body>
  <div>
  	
  	<div>
  		<h3>
  			<c:if test="${user.usertype==1 }">${user.nickname }--图书系统管理员--</c:if>
  			<c:if test="${user.usertype==0 }">${user.nickname }--普通用户--</c:if>
  			欢迎你
  		</h3>
  	</div>
  	<div>
  		<div><h1>图书详细信息列表</h1></div>
  		<div>
  			<table>
  				<tr>
  					<th>书名</th>
  					<th>作者</th>
  					<th>出版社</th>
  					<th>出版日期</th>
  					<th>页数</th>
  					<th>价格</th>
  					<th>内容摘要</th>
  					<th id="th">操作</th>
  				</tr>
  				<c:forEach items="${list }" var="li">
  				<tr>
  					<td>${li.name }</td>
  					<td>${li.author }</td>
  					<td>${li.publish }</td>
  					<td>${li.publishdate }</td>
  					<td>${li.page }</td>
  					<td>${li.price }</td>
  					<td>${li.content }</td>
  					<td class="td">
  						<a href="book/findById?id=${li.id }" id="update">修改</a>
  						<a href="book/delete?id=${li.id }" id="delete">删除</a>
  					</td>
  				</tr>
  				</c:forEach>
  			</table>
  		</div>
  		<div>
  			<input type="button" value="新增图书" onclick="location.href='addBook.jsp'" id="add"/>
  			<form action="book/findAll">
  			共${count }条数据
  			每页<input type="text" name="pageSize" value="${pageSize }"/>条
  			第${indexPage }/共${countPage }页
  			<a href="book/findAll?indexPage=1&pageSize=${pageSize }">第一页</a>
  			<c:if test="${indexPage==1 }">
  				<a href="book/findAll?indexPage=1&pageSize=${pageSize }">上一页</a>
  			</c:if>
  			<c:if test="${indexPage>1 }">
  				<a href="book/findAll?indexPage=${indexPage-1 }&pageSize=${pageSize }">上一页</a>
  			</c:if>
  			<c:if test="${indexPage<countPage }">
  				<a href="book/findAll?indexPage=${indexPage+1 }&pageSize=${pageSize }">下一页</a>
  			</c:if>
  			<c:if test="${indexPage==countPage }">
  				<a href="book/findAll?indexPage=${countPage }&pageSize=${pageSize }">下一页</a>
  			</c:if>
  			
  			<a href="book/findAll?indexPage=${countPage }&pageSize=${pageSize }">最后一页</a>
  			转到<input type="text" name="indexPage" value="${indexPage }"/>页<input type="submit" value="转到"/>
  			</form>
  		</div>
  	</div>
  </div>
  </body>
  <script type="text/javascript" src="JS/jquery-1.7.2.min.js"></script>
  <script type="text/javascript">
  	if('${user}'==""||'${user}'==null){
  		alert("请先登录");
  		location.href="login.jsp";
  	}
  	if('${list}'==""||'${list}'==null){
  		location.href="book/findAll";
  	}
  	
  	if('${user.usertype}'==0){
  		$('#add').hide();
  		$('.td').hide();
  		$('#th').hide();
  	}
  	if('${flag}'==2){
		alert("删除失败");
		location.href="index.jsp";
	}
	if('${flag}'==1){
		alert("删除成功");
		location.href="index.jsp";
	}
  	if('${flag1}'==2){
		alert("添加失败");
		location.href="index.jsp";
	}
	if('${flag1}'==1){
		alert("添加成功");
		location.href="index.jsp";
	}
  	if('${flag2}'==2){
		alert("添加失败");
		location.href="index.jsp";
	}
	if('${flag2}'==1){
		alert("添加成功");
		location.href="index.jsp";
	}
  	
  
  </script>
</html>
